<template>
  <div class="reportInfo">
    <div class="tableConten">
      <span class="redPoint">*</span>
      <div class="itemTitle">项目概况:</div>
      <div class="tebleDiv">
        <el-input
          type="textarea"
          :rows="4"
          placeholder="请输入项目概况"
          v-model="desc"
          :disabled="!isEdit"
        ></el-input>
      </div>
    </div>
    <div class="tableConten">
      <div class="itemTitle">关联业务单:</div>
      <div class="tebleDiv">
        <editTableNew
          :tableSetting="businessOrderSetting"
          :tableData="tableData"
          :hideBtn="hideBtn"
          ref="businessOrder"
        ></editTableNew>
      </div>
    </div>
    <div class="attachContent">
      <div class="attachTitle">附件:</div>
      <div class="tebleDiv">
        <attachFormNew
          style="width: 60%"
          :disabled="!isEdit"
          multiple
          :attachSetting="attachSetting"
          isDelete
          ref="attachFile"
        ></attachFormNew>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getReportApi, //获取大修报告
  saveReportApi, //保存大修报告
} from "@/api/orderManagement/overhaul";
export default {
  components: {},
  props: {
    formData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    pageType: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      orderStatus: "",
      desc: "",
      hideBtn: false,
      reportData: {},
      tableData: [],
      currentMajor: {},
      businessOrderSetting: {
        title: "",
        select: false,
        maxHeight: "100%",
        data: [],
        column: [
          {
            label: "业务类型",
            textAlign: "center",
            type: "text",
            prop: "type",
            required: true,
          },
          {
            label: "业务标题",
            textAlign: "center",
            prop: "tools",
            type: "textarea",
            autosize: true,
            required: true,
          },
          {
            label: "业务编号",
            textAlign: "center",
            prop: "tools",
            type: "textarea",
            autosize: true,
            required: true,
          },
        ],
        buttonArr: [
          {
            name: "详情",
            isShow: (row) => {
              return true;
            },
            methods: (row, index) => {
              this.details(row, index);
            },
          },
        ],
      },
      //附件设置
      attachSetting: {
        businessId: "", //单据的ID
        businessType: "report",
      },
    };
  },
  computed: {
    isEdit() {
      return (
        this.formData.status == "PREPARE_REPORT" && this.pageType == "edit"
      );
    },
  },
  watch: {
    formData: {
      handler(val) {
        this.attachSetting.businessId = this.formData.id;
        this.getReport();
      },
      deep: true,
      immediate: true,
    },
  },
  created() {},
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.getReport();
    },
    getReport() {
      getReportApi(this.formData.id).then((res) => {
        this.desc = this.reportData.desc;
        this.reportData = res.data || {};
      });
    },
    saveReport(type) {
      let form = {
        desc: this.desc,
        overhaulId: this.formData.id,
      };
      if (this.desc == ""&&type == "submit") {
        this.$message.warning("项目概况不能为空");
      } else {
        this.reportData = Object.assign(this.reportData, form);
        if (type == "submit") {
          this.$confirm(`提交后数据将会自动保存，是否继续`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.saveData(type);
            })
            .catch((e) => {});
        } else {
          this.saveData(type);
        }
      }
    },
    saveData(type) {
      saveReportApi(this.reportData).then((res) => {
        if (type == "submit") {
          this.$emit("perform");
          this.$utils.addOperateLog(this.formData.id, "提交-大修报告");
        } else {
          this.$utils.addOperateLog(this.formData.id, "保存-大修报告");
          this.$message.success("操作成功！");
          this.getReport();
        }
        this.saveAttachFile();
      });
    },

    //保存附件
    saveAttachFile() {
      this.$refs.attachFile.save();
    },
  },
};
</script>
<style lang="less">
.reportInfo {
  .attachContent {
    margin-top: 15px;
    display: flex;
    flex-flow: wrap nowrap;
    .redPoint {
      color: red;
    }
    .attachTitle {
      width: 120px;
    }
    .tebleDiv {
      width: 100%;
    }
  }
}
</style>

